import java.awt.Graphics;
import java.awt.Image;

public class ButterflySprite extends BeeSprite {
	protected Image imageButterflyLeft;
	protected Image imageButterflyRight;
	protected Image deadButterflyLeft;
	protected Image deadButterflyRight;

	protected boolean isHit;
	protected boolean shouldDrawImage = false;

	public boolean getIsHit() {
		return isHit;
	}

	public void setIsHit(boolean isHit) {
		this.isHit = isHit;
	}

	public ButterflySprite(Gameloop gl) {
		super(gl);

		imageButterflyLeft = ImageLoader.get().read("/Images/ButterflyLeft.png");
		imageButterflyRight = ImageLoader.get().read("/Images/ButterflyRight.png");

		deadButterflyLeft = ImageLoader.get().read("/Images/DeadButterflyLeft.png");
		deadButterflyRight = ImageLoader.get().read("/Images/DeadButterflyRight.png");

		speedx = 2.5f;
		speedy = 2.0f;

		maxlimit = 40;
		value = 2;
		isHit = false;
	}

	public void update() {

		if (isHit) {
			deadpath();
			shouldDrawImage = true;
			return;
		}

		if (++compteur % speedLimit == 0) {

			speedLimit = random.nextInt(maxlimit) + 1;

			flagy = random.nextBoolean();
			compteur = 0;
		}

		x = (int) (x + (speedx * (flagx ? 1 : -1)));
		y = (int) (y + (speedy * (flagy ? 1 : -1)));

	}

	public void draw(Graphics g) {

		if (!flagx && !isHit) {
			g.drawImage(imageButterflyLeft, x, y, width, height, null);
		} else if (flagx && !isHit) {
			g.drawImage(imageButterflyRight, x, y, width, height, null);
		} else if (isHit && !flagx) {
			g.drawImage(deadButterflyLeft, x, y, width, height, null);
		} else {
			g.drawImage(deadButterflyRight, x, y, width, height, null);
		}

	}

}
